layui.use(['form','layer','laydate','table','util'],function (){
    let form = layui.form,layer = layui.layer,laydate = layui.laydate,table = layui.table,util = layui.util;
    let dateElem = $('.form-dateElem');
    //渲染日期模块，最大日期为当前日期
    layui.each(dateElem,function () {
        laydate.render({
            elem:this,
            //最大日期比今天多几天
            max:0,
        })
    })

    //监听table，修改捆号、页数
    table.on('tool(fistDataTable)',function (obj) {

        // 获取所在行的相关数据中的业务申请编号
        let ciBussId = obj.data.ciBussId;
        //全局变量传值，使子页面可以获取
        setValue("atBussId",ciBussId);
        parent.layer.open({
            title:'档案受理信息',
            type:2,
            resize:false,
            area:['550px','590px'],
            content: '/business/archivesSearch/showAceptInfo'
        });
    });
})

/**
* @author: ChengJW
* @params:
* @return:
* @date: 2021/9/22
* @description: 初始化生成table数据
*/
$(function () {
    selectCompanyInfoList();
})

/**
* @author: ChengJW
* @params:
* @return:
* @date: 2021/9/22
* @description: 生成table数据
*/
function selectCompanyInfoList() {
    //起始日期
    let stDt = $('#stDt').val();
    //截止日期
    let lmDt = $('#lmDt').val();
    //查询条件类型
    let srchReqFir = $("select[name = 'srchReqFir']").val();
    //查询条件
    let qryReqFir = $("input[name = 'qryReqFir']").val().trim();

    let stDtClean = valueClean(stDt,"-");
    let lmDtClean = valueClean(lmDt,"-");
    if (!valueIsEmpty(stDt) && ! valueIsEmpty(lmDt) && stDtClean > lmDtClean){
        top.layer.alert("起始日期不能大于截止日期");
        return;
    }
    let jsonData = {
        "srchReqFir" : srchReqFir,
        "qryReqFir" : qryReqFir,
        "stDt" : stDt,
        "lmDt" : lmDt
    }
    //时间戳
    let tableTitle = '档案信息表'+layui.util.toDateString(new Date(),'yyyyMMddHHmmss');
    layui.table.render({
        elem:'#dataTable',
        id:'dataTableId',
        url:'/business/acceptAdmin/queryCompanyInfo',
        headers:{"token":getSysToken("token")},
        parseData:function (result) {
            return{
                "code":result.code,
                "msg":result.msg,
                "count":result.data.pageCount,
                "data":result.data.list
            }
        },
        size:'sm',
        //分页的起止页号，每页条数
        page:{
            curr:1,
            limit:15,
            limits:[15,30,50,100]
        },
        //自定义的页码参数名称、每页条数参数名称
        request:{
            pageName:'pageNum',
            limitName:'pageSize'
        },
        //table的高度
        height:550,
        //查询条件，json格式
        where:jsonData,
        cols:[[
            {type:'numbers',title:'序号'},
            {field:'ciRegistId',title:'注册号'},
            {field:'ciNm',title:'企业名称'},
            {field:'ciCreditCode',title:'统一社会信用代码'},
            {field:'ciPripalNm',title:'法人(负责人)',width: 100},
            {field:'ciRegistDeptNm',title:'登记机关'},
            {field:'ciMgeNm',title:'管辖机关'},
            {field:'ciRegistDt',title:'成立日期',width: 100,templet:function (d) {
                    return layui.util.toDateString(d.ciRegistDt,'yyyy-MM-dd');
                }},
            {field:'ciOpenLimitDt',title:'营业期限',width: 100,templet:function (d) {
                    return layui.util.toDateString(d.ciOpenLimitDt,'yyyy-MM-dd');
                }},
            {field:'ciRegistAmt',title:'注册资金',width: 100},
            {field:'ciType',title:'企业类型',width: 100},
            {field:'ciCheckDt',title:'核准日期',width: 100,templet:function (d) {
                    return layui.util.toDateString(d.ciCheckDt,'yyyy-MM-dd');
                }},
            {title:'操作',fixed:'right',width:100,align:'center',toolbar:'#toolBar'},
            {field:'ciBussId',title:'业务申请编号',hide:true},
        ]],
        //头部工具条
        toolbar: true,
        //导出时候excel文件标题
        title:tableTitle
    });
}